package com.woniuxy.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.env.BasicIniEnvironment;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @Author: 马宇航
 * @Do: 通过配置文件，进行认证操作
 * @DateTime: 22/05/19/0019 下午 5:28
 * @Component: 成都蜗牛学苑
 **/
public class AuthManager {
    public static void main(String[] args) {
        //前面是固定写法
        BasicIniEnvironment basicIniEnvironment = new BasicIniEnvironment("classpath:inifile/shiro-auth.ini");
        //生成shiro的核心管理器
        SecurityManager securityManager = basicIniEnvironment.getSecurityManager();
        SecurityUtils.setSecurityManager(securityManager);
        //subject：可以代指用户
        Subject subject = SecurityUtils.getSubject();
        //直接执行subject登录校验
        subject.login(new UsernamePasswordToken("mayun","1234567"));
        System.out.println(subject.isAuthenticated());
    }
}
